# Maintainer: Feng Shu <tumashu@163.com>

_realname=liberime
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.5
pkgrel=2
pkgdesc="An emacs dynamic module provide librime bindings for emacs (mingw-w64)"
arch=('any')
url="https://github.com/merrickluo/liberime"
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-librime")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
# checkdepends=("${MINGW_PACKAGE_PREFIX}-gtest")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/merrickluo/liberime/archive/v${pkgver}.tar.gz")
sha256sums=('0430402c5959df603a56df259787befa5e687ca95520c1c2e8ff7b84a2f832eb')

prepare() {
   cd "${_realname}-${pkgver}"
}

build() {
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    "../${_realname}-${pkgver}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  install -Dm644 liberime-core.dll ${pkgdir}${MINGW_PREFIX}/bin/liberime-core.dll
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/README.org ${pkgdir}${MINGW_PREFIX}/share/liberime/README.org
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/liberime.el ${pkgdir}${MINGW_PREFIX}/share/emacs/site-lisp/liberime.el
}
